//
//  RwdDiscoverController.swift
//  Weibo_rwd
//
//  Created by 任文迪 on 16/7/9.
//  Copyright © 2016年 spaceX. All rights reserved.
//

import UIKit

class RwdDiscoverController: RwdCommonController {

    override func viewDidLoad() {
        super.viewDidLoad()
        SetUpUI()
        
        if isLogin {
            
            
        }else{
            
            visitorView?.updateVisitorInfos("登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过", imageName: "visitordiscover_image_message")
            
        }
        
    }
    
    private func SetUpUI() {
        
        let searchView = RwdSearchView.searchView()
        
        navigationItem.titleView = searchView
        
        searchView.frame.size.width = self.view.frame.size.width
        
        tabBarItem.badgeValue = "hehe"
        
        for tabBarChild in (tabBarController?.tabBar.subviews)! {
            //打印子控件
//            print(tabBarChild)
            //再次筛选
            if tabBarChild.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                
                for tabBarButtonChild in tabBarChild.subviews {
                    //再次筛选子类
//                    print(tabBarButtonChild)
                    //_uibadgeView
                    if tabBarButtonChild.isKindOfClass(NSClassFromString("_UIBadgeView")!){
                        
                        for badgeViewChild in tabBarButtonChild.subviews {
                            
//                            print(badgeViewChild)
//                            _UIBadgeBackground
                            if badgeViewChild.isKindOfClass(NSClassFromString("_UIBadgeBackground")!){

                                    
                                    // 统计我们这个类里面有多少个成员变量
                                    var count: UInt32 = 0
                                    //  获取里面的成员列表
                                    let ivars = class_copyIvarList(NSClassFromString("_UIBadgeBackground")!, &count)
                                    
                                    for i in 0..<count {
                                        //  获取指定位置的成员
                                        let ivar = ivars[Int(i)]
                                        //  获取成员名字
                                        let name = ivar_getName(ivar)
                                        let type = ivar_getTypeEncoding(ivar)
                                        //  把获取的成员名字转字符串
                                        let nameStr = String(CString: name, encoding: NSUTF8StringEncoding)
                                        let typeStr = String(CString: type, encoding: NSUTF8StringEncoding)
                                        print(nameStr)
                                        print(typeStr)
                                        //  使用kvc方式给我们_image成员变量赋值
                                        if nameStr == "_image" {
                                            badgeViewChild.setValue(UIImage(named: "main_badge"), forKey: "_image")
                                        }
                                        
                                    }
                                }
                                
                            }
                            
                            
                        }
                        
                    }
                    
                    
                }
                
            }
            
        }
        
        
    }
    

    


